<template>
  <div class="myApp h100">
    <dividerTitle :title="componentTitle">
      <el-popover
        placement="bottom"
        width="300"
        trigger="click"
        popper-class="appPoper"
      >
        <div class="blockContent">
          <div class="blockTitle">
            <div class="notice-text">点击显示或隐藏</div>
          </div>
          <div class="blockMiddle">
            <div
              class="content-item"
              @click="showOrHide(item)"
              v-for="(item, index) in appDataArr"
              :key="index"
            >
              <el-card
                shadow="hover"
                :class="{
                  activeClass: item.status == true,
                  inactiveClass: item.status == false,
                }"
              >
                {{ item.name }}
              </el-card>
            </div>
          </div>
        </div>
        <el-button
          slot="reference"
          type="plain"
          size="mini"
          icon="iconfont icon-tiaozheng"
        ></el-button>
      </el-popover>
    </dividerTitle>
    <div class="appContent">
      <div class="my-app">
        <div
          v-show="item.status == true"
          class="app-item"
          v-for="(item, i) in appData"
          :key="i"
          @click="goAppDetailPage(item)"
        >
          <div class="app-logo">
            <el-image :src="item.imgSrc"></el-image>
            <div
              style="
                margin: 0 auto;
                margin-top: 3px;
                font-size: 16px;
                font-weight: 450;
              "
            >
              {{ item.name }}
            </div>
          </div>
        </div>
        <div
          v-show="item.status == true"
          class="app-item"
          v-for="(item) in outerAppDate"
          :key="item.code"
          @click="goOuterAppDetailPage(item)"
        >
          <div class="app-logo">
            <el-image :src="item.imgSrc"></el-image>
            <div
              style="
                margin: 0 auto;
                margin-top: 3px;
                font-size: 16px;
                font-weight: 450;
              "
            >
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getAddressAfter } from "@/api/orderManagement/spotCheck.js";
export default {
  props: ["componentTitle"],
  data() {
    return {
      appDataArr: this.$store.state.user.allAuth.appList,
      appData: [], //this.$store.state.user.allAuth.appList,
      // 跳转外部app应用
      outerAppDate: [
        // {
        //   code: "remoteSupport",
        //   name: "远程协助",
        //   link: `https://10.21.21.87?userId=${this.$store.getters.currentInfo.currLeader}`,
        //   status: true,
        //   imgSrc: require("@/assets/img/workStation/remoteSupport.png"),
        // }
      ],
      componentList: [
        {
          name: "workCalender",
          label: "工作历",
          status: true,
        },
        {
          name: "myApp",
          label: "我的应用",
          status: true,
        },
        {
          name: "productionCockpit",
          label: "生产驾驶舱",
          status: true,
        },
        {
          name: "dutyToday",
          label: "今日值班",
          status: false,
        },
        {
          name: "workCalender",
          label: "工作历",
          status: true,
        },
        {
          name: "myApp",
          label: "我的应用",
          status: false,
        },
        {
          name: "productionCockpit",
          label: "生产驾驶舱",
          status: false,
        },
        {
          name: "myApp",
          label: "我的应用",
          status: false,
        },
      ],
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.appData = this.appDataArr;
    },
    showOrHide(item) {
      item.status = !item.status;
    },
    // 跳转至外部应用
    goOuterAppDetailPage(app) {
      window.open(app.link, "_blank");
    },
    goAppDetailPage(app) {
      if(app.link) {
        if(app.code === 'remoteSupport') {
          app.link = `https://10.21.21.87?userId=${this.$store.getters.currentInfo.currLeader}`
          this.goOuterAppDetailPage(app)
        }
      }
      if (app.code == "intelligentInspection") {
        this.goInspection();
      } else {
        let { href } = this.$router.resolve({
          path: app.router,
          params: {
            name: app.name,
            logoSrc: app.logoSrc,
          },
        });
        window.open(href, "_blank");
      }
    },
    //前往智能巡检系统
    goInspection() {
      let param = {
        classifyCode: "common",
        code: "intelligent_inspection_url",
      };
      getAddressAfter(param)
        .then((res) => {
          if (res.code == 200) {
            let currentData = res.data ? res.data.configDetailList : [];
            if (currentData.length > 0) {
              let href = currentData[0].value;
              window.open(href, "_blank");
            }
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
  },
};
</script>
<style>
.appPoper {
  border-radius: 8px;
  transform: translateX(-10px);
  padding: 0 0 6px 0;
}
</style>
<style lang="less" scoped>
.appContent {
  height: calc(100% - 60px);
  position: relative;
  top: -6px;
  .my-app {
    height: 100%;
    overflow-y: auto;
    .app-item {
      cursor: pointer;
      float: left;
      height: 86px;
      width: 12%;
      margin: 4px 0px 6px 5px;
      .app-logo {
        margin: 0 auto;
        border-radius: 10px;
        //margin: 5px 10px;
        /deep/.el-image {
          width: 48px;
          height: 48px;
          -moz-transition: all 0.3s ease; /* FF3.7+ */
          -o-transition: all 0.3s ease; /* Opera 10.5 */
          -webkit-transition: all 0.3s ease; /* Saf3.2+, Chrome */
          transition: all 0.3s ease;
        }
      }
      .app-logo:hover {
        position: relative;
        top: -10px;
        width: 70%;
        background-color: rgb(248, 248, 248);
        margin: 10px auto;
        .el-image {
          width: 58px;
          height: 58px;

          //box-shadow: 0 0 10px rgba(18, 164, 228, 0.5);
        }
      }
    }
  }
}
/deep/.blockContent {
  display: flex;
  flex-direction: row;
}
/deep/.blockTitle {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
/deep/.notice-text {
  padding: 19px 0px 12px 16px;
  color: #999999;
}
/deep/.grid-text {
  padding: 19px 16px 12px 0px;
  color: #666666;
  cursor: pointer;
}
/deep/.content-item {
  margin-right: 12px;
  margin-bottom: 18px;
  border-radius: 4px;
  width: 45%;
  height: 40px;
  float: left;
  cursor: pointer;
  &:nth-child(2n) {
    margin-right: 0px;
  }
}
/deep/.el-card__body {
  padding: 13px 0;
  text-align: center;
}
/deep/.blockMiddle {
  margin-left: 16px;
  max-height: 465px;
  overflow-y: auto;
}
.activeClass {
  color: #0d60b4;
  background: #eef5fc;
}
.inactiveClass {
  color: #666666;
  background: #f8f8f8;
}

/deep/.el-button--plain {
  border: none;
  font-size: 16px;
}
</style>